<?php
//全景评论
if(!defined('IN_T')){
   die('hacking attempt');
}

//删除评论
if($act=='delete'){
	$cid = intval($_POST['cid']);
	$sql = "delete from ".$Base->table('comment')." where id=$cid";
	$Db->execSql($sql);
	echo $Json->encode(array('status'=>1));
	exit;
}
//显示评论
else{
	$time_s = Common::sfilter($_REQUEST['time_s']);
	$time_e = Common::sfilter($_REQUEST['time_e']);
	$name = Common::sfilter($_REQUEST['name']);	//作品名称
	$page = intval($_REQUEST['page']);
	$page = $page<1 ? 1 : $page;
	$pageSize = 20;
	$res = get_works_comments($name,$page,$pageSize,$time_s,$time_e);
	$pages = Common::set_page($pageSize,$page,$res['count']);
	foreach ($pages as $key => $value) {
		$pages[$key]['url'] = "/".TONGJI_PATH."/?m=comment&page=".$value['num'].$res['spm'];
	}
	$tp->assign("page",$page);
	$tp->assign("pages",$pages);
	//print_r($res);
	$tp->assign('res',$res);
}
$tp->assign('nav','全景评论');

//提取全景评论
function get_works_comments($name,$page,$pageSize,$time_s,$time_e){
	global $Base,$tp,$Db;
	$sql = "select c.*,w.name,w.thumb_path,w.view_uuid from ".$Base->table('comment')." as c ".
	       "left join ".$Base->table('worksmain')." as w on w.pk_works_main=c.pk_works_main ".
		   "where 1 ";
	$spm = '';
	if(!empty($name)){
		$sql .= "and w.name like '%$name%' ";
		$spm .= "&name=$name";
		$tp->assign('name',$name);
	}   
	if(!empty($time_s)){
		$sql .= "and add_time>'$time_s' ";
		$spm .= "&time_s=$time_s";
		$tp->assign('time_s',$time_s);
	}
	if(!empty($time_e)){
		$sql .= "and add_time<'$time_e' ";
		$spm .= "&time_e=$time_e";
		$tp->assign('time_e',$time_e);
	}
	//echo $sql;
	$count = count($Db->query($sql));
	$sql .= "order by c.id desc limit ".($page-1)*$pageSize.", $pageSize";
	$res = $Db->query($sql);
	return array('count'=>$count,'res'=>$res,'spm'=>$spm);
}
?>